import {Message} from 'element-ui'
/**
 * 时间戳转时间字符串
 * @param {时间戳} timestamp 
 */
export function getTimeString(timestamp) {
    if (timestamp == undefined) {
        return [""]
    }

    var now = new Date(Number(timestamp));
    var year = now.getFullYear();
    var month = (now.getMonth() + 1 < 10 ? '0' + (now.getMonth() + 1) : (now.getMonth() + 1) + '');
    var date = (now.getDate() < 10 ? '0' + (now.getDate()) : now.getDate()) + '';
    var hour = (now.getHours() < 10 ? '0' + (now.getHours()) : now.getHours() + '');
    var minute = (now.getMinutes() < 10 ? '0' + (now.getMinutes()) : now.getMinutes() + '');
    // var second = (now.getSeconds() < 10 ? '0' + (now.getSeconds()) : now.getSeconds() + '');

    return [
        year + "-" + month + "-" + date + " " + hour + ":" + minute, year + "-" + month + "-" + date
    ]
}

/**
 * 时间 yyyy-MM-dd HH:mm:ss 转时间戳
 * @param {时间} time 
 */
export function timeToTimeStamp(time) {
    var timeStamp = new Date(time).getTime();
    return timeStamp;
}

/**
 * 
 * @param {获取当前年月日} 
 */
export function getNowTime(){
    var now = new Date();
    var year = now.getFullYear();
    var month = (now.getMonth() + 1 < 10 ? '0' + (now.getMonth() + 1) : (now.getMonth() + 1) + '');
    var date = (now.getDate() < 10 ? '0' + (now.getDate()) : now.getDate()) + '';
    // var hour = (now.getHours() < 10 ? '0' + (now.getHours()) : now.getHours() + '');
    // var minute = (now.getMinutes() < 10 ? '0' + (now.getMinutes()) : now.getMinutes() + '');
    return [
        year + month + date,
        year
    ]
}


/**
 * 
 * @param {内容} str 
 */
export function copy(str) {
    var input = document.createElement("input");   // 直接构建input
    input.value = str;  // 设置内容
    document.body.appendChild(input);    // 添加临时实例
    input.select();   // 选择实例内容
    document.execCommand("Copy");   // 执行复制
    Message({
        message:"复制成功",
        type: 'success',
    })
    document.body.removeChild(input); // 删除临时实
}



